package com.tcmj.dining.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.tcmj.common.annotation.Log;
import com.tcmj.common.enums.BusinessType;
import com.tcmj.dining.domain.TzDiningRoom;
import com.tcmj.dining.domain.TzVagetables;
import com.tcmj.dining.service.ITzDiningRoomService;
import com.tcmj.dining.service.ITzVagetablesService;
import com.tcmj.common.core.controller.BaseController;
import com.tcmj.common.core.domain.AjaxResult;
import com.tcmj.common.utils.poi.ExcelUtil;
import com.tcmj.common.core.page.TableDataInfo;

/**
 * 菜品Controller
 * 
 * @author tcmj
 * @date 2020-05-17
 */
@Controller
@RequestMapping("/system/vagetables")
public class TzVagetablesController extends BaseController
{
    private String prefix = "system/vagetables";

    @Autowired
    private ITzVagetablesService tzVagetablesService;
    
    @Autowired
    private ITzDiningRoomService tzDiningRoomService;

    @RequiresPermissions("system:vagetables:view")
    @GetMapping()
    public String vagetables()
    {
        return prefix + "/vagetables";
    }

    /**
     * 查询菜品列表
     */
    @RequiresPermissions("system:vagetables:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TzVagetables tzVagetables)
    {
        startPage();
        List<TzVagetables> list = tzVagetablesService.selectTzVagetablesList(tzVagetables);
        return getDataTable(list);
    }

    /**
     * 导出菜品列表
     */
    @RequiresPermissions("system:vagetables:export")
    @Log(title = "菜品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TzVagetables tzVagetables)
    {
        List<TzVagetables> list = tzVagetablesService.selectTzVagetablesList(tzVagetables);
        ExcelUtil<TzVagetables> util = new ExcelUtil<TzVagetables>(TzVagetables.class);
        return util.exportExcel(list, "vagetables");
    }

    /**
     * 新增菜品
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
    	mmap.put("tzDiningRooms", tzDiningRoomService.selectTzDiningRoomList(new TzDiningRoom()));
        return prefix + "/add";
    }

    /**
     * 新增保存菜品
     */
    @RequiresPermissions("system:vagetables:add")
    @Log(title = "菜品", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TzVagetables tzVagetables)
    {
        return toAjax(tzVagetablesService.insertTzVagetables(tzVagetables));
    }

    /**
     * 修改菜品
     */
    @GetMapping("/edit/{vagetablesId}")
    public String edit(@PathVariable("vagetablesId") Long vagetablesId, ModelMap mmap)
    {
        TzVagetables tzVagetables = tzVagetablesService.selectTzVagetablesById(vagetablesId);
        mmap.put("tzVagetables", tzVagetables);
        
        mmap.put("tzDiningRooms", tzDiningRoomService.selectTzDiningRoomList(new TzDiningRoom()));
        return prefix + "/edit";
    }

    /**
     * 修改保存菜品
     */
    @RequiresPermissions("system:vagetables:edit")
    @Log(title = "菜品", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TzVagetables tzVagetables)
    {
    	
        return toAjax(tzVagetablesService.updateTzVagetables(tzVagetables));
    }

    /**
     * 删除菜品
     */
    @RequiresPermissions("system:vagetables:remove")
    @Log(title = "菜品", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tzVagetablesService.deleteTzVagetablesByIds(ids));
    }
}
